﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharedGenomics.Core
{
    public class TextDataRow
    {
        private KeyedIndexedCollection<string, string> _columnNames;

        public TextDataRow(IEnumerable<string> columnNames)
        {
            this._columnNames = new KeyedIndexedCollection<string, string>(s => s, StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);
            this._columnNames.AddRange(columnNames);
        }

        public virtual string[] ColumnData { private get; set; }

        public virtual string this[string columnName]
        {
            get
            {
                columnName.ThrowIfNull("columnName");

                return this._columnNames.ContainsKey(columnName)
                    ? this[this._columnNames.GetItemIndex(columnName)]
                    : String.Empty;
            }
        }

        public virtual string this[int columnIndex]
        {
            get
            {
                ExceptionHelper.ThrowIf<IndexOutOfRangeException>(columnIndex < 0, "Index must be greater than 0");

                return this.ColumnData != null && columnIndex < this.ColumnData.Length
                    ? this.ColumnData[columnIndex]
                    : String.Empty;
            }
        }
    }
}
